package com.swancloud.openstack.networking.v20210120.domain.ext.fwaas;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonRootName;
import com.google.common.base.MoreObjects;
import com.swancloud.model.network.v20210120.fwaas.FirewallUpdate;
import com.swancloud.model.network.v20210120.fwaas.builder.FirewallUpdateBuilder;

import java.util.List;

/**
 * An entity used to update Neutron Firewall (FwaaS).
 *
 * @author Vishvesh Deshmukh
 */
@JsonRootName("firewall_group")
@JsonIgnoreProperties(ignoreUnknown = true)
public class NeutronFirewallUpdate implements FirewallUpdate {

	private static final long serialVersionUID = 1L;

	private String name;

	private String description;

	private Boolean shared;

	@JsonProperty("admin_state_up")
    private Boolean adminStateUp;

	@JsonProperty("ingress_firewall_policy_id")
	private String ingressPolicyId;

	@JsonProperty("egress_firewall_policy_id")
	private String egressPolicyId;

	private List<String> portIds;
	/**
	 * Wrap this Firewall to a builder
	 * @return FirewallUpdateBuilder
	 */
	@Override
	public FirewallUpdateBuilder toBuilder() {
		return new FirewallUpdateConcreteBuilder(this);
	}

	/**
	 * @return FirewallUpdateBuilder
	 */
	public static FirewallUpdateBuilder builder() {
		return new FirewallUpdateConcreteBuilder();
	}

	@Override
	public String getName() {
		return name;
	}

	@Override
	public String getDescription() {
		return description;
	}

	@Override
	public Boolean isAdminStateUp() {
		return adminStateUp != null && adminStateUp;
	}

	@Override
	public Boolean isShared() {
		return shared != null && shared;
	}

	@Override
	public String getIngressPolicyId() {
		return ingressPolicyId;
	}

	@Override
	public String getEgressPolicyId() {
		return egressPolicyId;
	}

	@Override
	public List<String> portIds() {
		return portIds;
	}

	@Override
	public String toString() {
		return MoreObjects.toStringHelper(this).omitNullValues()
				.add("name", name).add("ingressPolicyId", ingressPolicyId).add("egressPolicyId",egressPolicyId)
				.add("shared", shared).add("adminStateUp", adminStateUp)
				.add("ports", portIds).add("description", description)
				.toString();
	}

	public static class FirewallUpdateConcreteBuilder implements FirewallUpdateBuilder {
		NeutronFirewallUpdate f;

		@Override
		public FirewallUpdate build() {
			return f;
		}

		public FirewallUpdateConcreteBuilder() {
			this(new NeutronFirewallUpdate());
		}

		public FirewallUpdateConcreteBuilder(NeutronFirewallUpdate f) {
			this.f = f;
		}

		@Override
		public FirewallUpdateBuilder from(FirewallUpdate in) {
			this.f = (NeutronFirewallUpdate) in;
			return this;
		}

		@Override
		public FirewallUpdateBuilder name(String name) {
			f.name = name;
			return this;
		}

		@Override
		public FirewallUpdateBuilder description(String description) {
			f.description = description;
			return this;
		}

		@Override
		public FirewallUpdateBuilder adminStateUp(Boolean adminStateUp) {
			f.adminStateUp = adminStateUp;
			return this;
		}

		@Override
		public FirewallUpdateBuilder shared(Boolean shared) {
			f.shared = shared;
			return this;
		}

		@Override
		public FirewallUpdateBuilder ingressPolicyId(String policyId) {
			f.ingressPolicyId = policyId;
			return this;
		}

		@Override
		public FirewallUpdateBuilder egressPolicyId(String policyId) {
			f.egressPolicyId = policyId;
			return this;
		}

		@Override
		public FirewallUpdateBuilder portIds(List<String> portIds) {
			f.portIds = portIds;
			return this;
		}

	}

}
